package com.lcf.mytccaccount.concurrent;

import java.util.concurrent.*;

public class SingletonExecutor extends ThreadPoolExecutor {
    private static final int QUEUE_SIZE = 5000;
    /**
     * thread name.
     */
    private String name;
    private static final RejectedExecutionHandler HANDLER = new MyRejectedExecutionHandler();

    /**
     * public ThreadPoolExecutor(int corePoolSize,
     * int maximumPoolSize,
     * long keepAliveTime,
     * TimeUnit unit,
     * BlockingQueue<Runnable> workQueue,
     * ThreadFactory threadFactory) {
     * this(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue,
     * threadFactory, defaultHandler);
     *
     * @param poolName
     */
    public SingletonExecutor(final String poolName) {
        super(1, 1, 10L,
                TimeUnit.MILLISECONDS,
//                new LinkedBlockingQueue<>(QUEUE_SIZE),
                new ArrayBlockingQueue<Runnable>(3),
                HmilyThreadFactory.create(poolName, false),
                HANDLER);
        this.name = poolName;
    }

    /**
     * Gets name.
     *
     * @return the name
     */
    public String getName() {
        return name;
    }
}
